public class Solution223 {
    public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        int areaA = area(ax1, ay1, ax2, ay2);
        int areaB = area(bx1, by1, bx2, by2);
        int x = Math.max(0, Math.min(ax2, bx2) - Math.max(ax1, bx1));
        int y = Math.max(0, Math.min(ay2, by2) - Math.max(ay1, by1));

        return areaA + areaB - x * y;
    }

    public int area(int x1, int y1, int x2, int y2) {
        int length = x2 - x1;
        int height = y2 - y1;
        return length * height;
    }

    public static void main(String[] args) {

    }
}
